﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Wicresoft.EKA.NRemedy;
using System.Threading;
using System.Windows.Forms;
using Wicresoft.EKA.NRemedy.CodeGenerate;

namespace Wicresoft.EKA.NRemedy.CodeGenerator.WinForm
{
    public class SearchFormThread : ARThread
    {

        private static string _namelikes = string.Empty;

        public PushFormListDelegate SearchCompeleted;

        public SearchFormThread()
        {
            SearchCompeleted += new PushFormListDelegate(SearchFormThread_SearchCompeleted);
        }

        protected virtual void SearchFormThread_SearchCompeleted(IEnumerable<ARFormDisplay> formList)
        {
        }

        public void Start(string nameLikes)
        {
            _thread = new Thread(GetListRegularForm);
            _namelikes = nameLikes;
                _thread.Start();
        }

        private void GetListRegularForm(){
            if (GlobalCache.FormCache == null || GlobalCache.FormCache.Count == 0)
            {
                MessageBox.Show("未登录成功。");
            }
            else
            {
                var forms = GlobalCache.FormCache.Where(o => o.Name.Contains(_namelikes));
                if (SearchCompeleted != null)
                {
                    Control control = SearchCompeleted.Target as Control;
                    if (control != null)
                        control.Invoke(SearchCompeleted, forms);
                    else
                        SearchCompeleted(forms);
                }
            }
        }

        public static bool FormFinalFilter(BMC.ARSystem.ARForm form){
            return GetARFormFilterDelegate.FormFilterBase(form);
        }


    }
}
